package com.yugao.fintech.antelope.mps.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yugao.fintech.antelope.mps.mapper.MsgTemplateMapper;
import com.yugao.fintech.antelope.mps.model.entity.MsgTemplate;
import com.yugao.fintech.framework.assistant.utils.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 消息模板 仓储层
 */
@Slf4j
@Repository
public class MsgTemplateManager extends ServiceImpl<MsgTemplateMapper, MsgTemplate>
        implements IService<MsgTemplate> {

    /**
     * 获取被使能的模板
     */
    public List<MsgTemplate> listTemplateByTaskId(Long taskId, String channelType) {
        LambdaQueryWrapper<MsgTemplate> lqw = MsgTemplate.lqw().eq(MsgTemplate::getTaskId, taskId)
                .eq(StringUtils.isNotEmpty(channelType), MsgTemplate::getChannelType, channelType)
                .eq(MsgTemplate::getStatus, true);
        return this.list(lqw);
    }

    public List<MsgTemplate> listTemplateByTaskIds(List<Long> taskIds, String channelType) {
        LambdaQueryWrapper<MsgTemplate> lqw = MsgTemplate.lqw().in(MsgTemplate::getTaskId, taskIds)
                .eq(StringUtils.isNotEmpty(channelType), MsgTemplate::getChannelType, channelType)
                .eq(MsgTemplate::getStatus, true);
        return this.list(lqw);
    }

    public void deleteTemplateByTaskIds(List<Long> taskIds) {
        if (CollectionUtils.isEmpty(taskIds)) {
            return;
        }
        LambdaQueryWrapper<MsgTemplate> lqw = MsgTemplate.lqw().in(MsgTemplate::getTaskId, taskIds);
        this.remove(lqw);
    }
}
